<html>
<head><meta charset="utf-8"><title>Unnecessary clone optimization · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unnecessary.20clone.20optimization.html">Unnecessary clone optimization</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203534536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unnecessary%20clone%20optimization/near/203534536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unnecessary.20clone.20optimization.html#203534536">(Jul 10 2020 at 17:21)</a>:</h4>
<p>Does the compiler do any  optimization if the user cloned a value that is dropped after the clone?</p>



<a name="203534683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unnecessary%20clone%20optimization/near/203534683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unnecessary.20clone.20optimization.html#203534683">(Jul 10 2020 at 17:22)</a>:</h4>
<p>LLVM is free to optimize away either if it can prove that the observable behavior doesn't change</p>



<a name="203534849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unnecessary%20clone%20optimization/near/203534849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unnecessary.20clone.20optimization.html#203534849">(Jul 10 2020 at 17:24)</a>:</h4>
<p>do you know where I can read a little more about how llvm proves that the change would be unobservable?</p>



<a name="203544489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Unnecessary%20clone%20optimization/near/203544489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Unnecessary.20clone.20optimization.html#203544489">(Jul 10 2020 at 18:52)</a>:</h4>
<p><span class="user-mention" data-user-id="132916">@Christian Poveda</span> This would probably involve inlining combined with in the case of memory allocations special knowledge about the observable behaviour of <code>malloc</code>, <code>free</code> and <code>memcpy</code>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>